home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr53
/
pctv4n_1.zip
/
XQLFUNCS.C
< prev
next >
Wrap
Text File
|
1993-06-11
|
7KB
|
348 lines
/**************************************************
* FILE NAME: XQLfuncs.c TITLE: SQL database API
*
* AUTHOR: K. E. North II
*
* SYNOPSIS:
*
* application interface to Novell's XQL and
* Netware SQL.
*
***************************************************/
#undef DEBUG
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <malloc.h>
#include "xqlintf.h"
#ifndef __XQLDEFS_H
/*XQL-specific definitions */
#include "xqldefs.h"
#endif
#ifndef __XCOLUMN_H
/* XQLM column description */
#include "xcolumn.h"
#endif
#ifndef __XQLCALLS_H
/* function prototypes for XQLM calls */
#include "xqlcalls.h"
#endif
#ifndef __DBTYPES_H
#include "dbtypes.h"
#endif
#ifndef __XQLFUNCS_H
/* portable SQL API functions */
#include "xqlfuncs.h"
#endif
/**************************************************
* FUNCTION NAME: dbClose
*
* SYNOPSIS:
*
* close a data base session - terminate connection
*
***************************************************/
int dbClose()
{
int ExitStatus;
ExitStatus = dbDisconnect(); /* to logout */
if (ExitStatus)
return ExitStatus;
else
return SQL_SUCCESS;
}
/**************************************************
* FUNCTION NAME: dbRequest
*
* SYNOPSIS:
*
* prepare an SQL request / statement
*
* for XQL/NWSQL:
*
* XQLCursor - request a cursor
* (reserve resources)
*
* XQLCompile - pass the SQL string to XQLM for
* compilation and execution (when appropriate)
*
***************************************************/
int dbRequest( REQUEST rq )
{
int XQLStatus;
int StatementLength;
HCUR CursorID;
XQLStatus = XQLCursor (&CursorID);
if (XQLStatus)
{
printf
("XQLCursor failed, XQLStatus: %d\n",
XQLStatus);
return XQLStatus;
};
/* save request's cursor */
rq->CursorID = CursorID;
/* get length of */
/* SQL command string */
StatementLength = strlen (rq->Statement);
XQLStatus = XQLCompile (rq->CursorID,
&StatementLength,
rq->Statement);
if (XQLStatus)
{
return XQLStatus;
}
return SQL_SUCCESS;
}
/**************************************************
* FUNCTION NAME: dbFetch
*
* AUTHOR: Ken North
*
* SYNOPSIS:
*
*
* XQLFetch - return data from XQLM
*
***************************************************/
int dbFetch (VIEWINFO vu, REQUEST rq, char *records)
{
int XQLStatus;
int ExitStatus;
XQLStatus = XQLFetch (rq->CursorID,
vu->FetchOption, &vu->BufferLen,
records, &vu->ReceiveCount,
vu->ASCIIFlag, vu->Spacing);
if (XQLStatus > 0)
{
return XQLStatus;
};
vu->RecordsGotten = vu->ReceiveCount;
return SQL_SUCCESS;
}
/**************************************************
* FUNCTION NAME: dbGetData
*
* SYNOPSIS:
*
* get data base records via XQLM
*
* use defaults for FetchOption, Spacing and ASCII
* format flag
*
***************************************************/
int dbGetData (VIEWINFO vu,
char *records, REQUEST rq)
{
int StatusReturned;
int XQLStatus;
vu->ASCIIFlag = STOREZEROS;
/* put one binary 0 after each value */
vu->Spacing = 1;
/* ReceiveCount = number of records to
retrieve on each fetch */
vu->BufferLen = vu->RowLength *
vu->ReceiveCount;
StatusReturned = dbFetch ( vu, rq, records);
if (StatusReturned != SQL_SUCCESS)
{
return XQLStatus;
};
return SQL_SUCCESS;
}
/**************************************************
* FUNCTION NAME: dbDescribe
*
* SYNOPSIS:
*
* access .ddf to retrieve list of fields
* via XQLDescribe
*
* data types for XQL:
*
* character 0 logical 7
* integer 1 numeric 8
* float 2 bfloat 9
* date 3 lstring 10
* time 4 zstring 11
* decimal 5 note 12
* money 6 lvar 13
*
***************************************************/
int dbDescribe(int ColumnPos,
struct ColumnDesc *col,
REQUEST rq)
{
int XQLStatus;
col->namelen = NAMELENGTH;
col->data_type = 0;
col->size = 0;
col->dec_places = 0;
col->display_len = 0;
strcpy(col->fldname," ");
XQLStatus = XQLDescribe (rq->CursorID,
ColumnPos + 1,
&col->data_type,
&col->size,
&col->dec_places,
&col->display_len,
&col->namelen,
col->fldname);
if (XQLStatus)
return XQLStatus;
else
return SQL_SUCCESS;
}
/**************************************************
* FUNCTION NAME: dbConnect
*
* SYNOPSIS:
* open an XQL/NWSQL connection
*
*
* XQLLogin() - establish a session
* XQL login to the data base
*
***************************************************/
int dbConnect(CONNECTION si)
{
int XQLStatus;
/********************************/
/* Login to XQLM / NWSQL */
/********************************/
XQLStatus = XQLLogin (si->userid, si->password,
si->dict_path, si->data_path,
si->reserved, 0);
if (XQLStatus)
{
return XQLStatus;
};
return SQL_SUCCESS;
}
/**************************************************
* FUNCTION NAME: dbDisconnect
*
* SYNOPSIS:
* exit an XQL/Netware SQL session
*
***************************************************/
int dbDisconnect()
{
int XQLStatus;
XQLStatus = XQLLogout ();
if (XQLStatus)
return XQLStatus;
else
return SQL_SUCCESS;
}
/**************************************************
* FUNCTION NAME: DecodeXQLDataType
*
* SYNOPSIS: return description of data type
*
***************************************************/
char *DecodeXQLDataType(int DataType)
{
static char Type[20];
strcpy(Type,"Unknown");
if (DataType == 0)
strcpy(Type,"character");
if (DataType == 1)
strcpy(Type,"integer");
if (DataType == 2)
strcpy(Type,"float");
if (DataType == 3)
strcpy(Type,"date");
if (DataType == 4)
strcpy(Type,"time");
if (DataType == 5)
strcpy(Type,"decimal");
if (DataType == 6)
strcpy(Type,"money");
if (DataType == 7)
strcpy(Type,"logical");
if (DataType == 8)
strcpy(Type,"numeric");
if (DataType == 9)
strcpy(Type,"bfloat");
if (DataType == 10)
strcpy(Type,"lstring");
if (DataType == 11)
strcpy(Type,"zstring");
if (DataType == 12)
strcpy(Type,"note");
if (DataType == 13)
strcpy(Type,"lvar");
return Type;
}
#ifdef DEBUG
/**************************************************
* FUNCTION NAME: pause()
*
* SYNOPSIS: prompt for key to continue
*
***************************************************/
void pause(void)
{
int c;
printf( "press a key to continue...\n" );
c = getch();
}
#endif